package logic

import (
	"context"
	"fmt"
	"manager/model/mysql"

	"manager/merchantmanager/internal/svc"
	"manager/merchantmanager/merchantmanager"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *merchantmanager.RequestUpdate) (*merchantmanager.ResponseUpdate, error) {
	// todo: add your logic here and delete this line
	var data mysql.Merchant
	data = mysql.Merchant{
		MerchantID:    int(in.MerchantID),
		MerchantName:  in.MerchantName,
		MerchantTypes: in.MerchantTypes,
		MerchantTime:  in.MerchantTime,
	}
	err := mysql.DB.Where("merchant_id=?", in.MerchantID).Updates(data).First(&data).Error
	if err != nil {
		return nil, fmt.Errorf("修改失败")
	}
	return &merchantmanager.ResponseUpdate{
		MerchantID: int64(data.MerchantID),
	}, nil
}
